package com.cyz.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyz.common.bean.UserRole;
import com.cyz.common.mapper.UserRoleMapper;
import com.cyz.common.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author 34928
* @description 针对表【user_role(用户和角色关联表)】的数据库操作Service实现
* @createDate 2023-02-24 08:58:49
*/
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole>
    implements UserRoleService {

    @Override
    public List<Integer> getRoleIdsByUserId(Integer id) {
        //创建筛选器
        LambdaQueryWrapper<UserRole> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //根据用户id查询角色id
        lambdaQueryWrapper.eq(UserRole::getUserId,id);
        //查询数据
        List<UserRole> list = list(lambdaQueryWrapper);
        //转化数据
        List<Integer> collect = list.stream()
                .map(UserRole::getRoleId)
                .collect(Collectors.toList());
        return collect;
    }

}




